﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SscLib
{
    /// <summary>
    /// Base class for Symbols to be added to the SymbolTable.
    /// All Symbols have a Name, Type and Scope.
    /// </summary>
    public class Symbol
    {
        /// <summary>Symbol Name.</summary>
        public readonly string Name;
        
        ///// <summary>The symbol type as found in the SymbolTable</summary>
        //public TypeSymbol Type;

        /// <summary>The SymbolTable Scope defining the Symbol</summary>
        public ScopeSymbol Scope;


        protected TypeSymbol _type;

        /// <summary>The symbol type as found in the SymbolTable</summary>        
        public virtual TypeSymbol Type
        {
            get { return this._type; }
            set { this._type = value; }
        }


        /// <summary>
        /// Creates a new Symbol with Name and Type.
        /// </summary>
        /// <param name="name">Symbol name.</param>
        /// <param name="type">Symbol type.</param>
        public Symbol(string name, TypeSymbol type)
        {
            this.Name = name;
            this.Type = type;
        }

        /// <summary>
        /// Returns the SystemType (Native .Net Type) of this Symbol.
        /// </summary>
        public virtual Type SystemType
        {
            get { return Type.SystemType; }
        }

        /// <summary>
        /// Returns a string that represents this symbol.
        /// </summary>
        /// <returns>String with name and type of the symbol.</returns>
        public override string ToString()
        {
            return Name + ":" +((this.Type != null) ? this.Type.Name : "---");
        }
    }
}
